<template>
	<view class="fui-wrap">
		<fui-sticky>
			<view style="background-color: #fff;">
				<fui-segmented-control @click="changeSegmented" :current="current" color="#000" activeColor="#0a8cdd" type="text" :values="segmented"></fui-segmented-control>
			</view>
		</fui-sticky>
		<fui-list>
			<fui-list-cell v-for="(item,index) in list" :key="index" :highlight="false">
				<view class="item" v-if="current===0">
					<view class="line-between">
						<view class="one-60">
							<fui-text text="停车车牌：" color="#afafaf" :size="28"></fui-text>
							<fui-text :text="item.records.plate_number" color="black" :size="28"></fui-text>
						</view>
						<view class="one-40">
							<fui-text text="费用：" color="#afafaf" :size="28"></fui-text>
							<fui-text :text="'￥'+parseNumber(item.records.total_fee)" color="black" :size="28"></fui-text>
						</view>
					</view>
					<view class="line-between">
						<view class="one-60">
							<fui-text text="结算时间：" color="#afafaf" :size="28"></fui-text>
							<fui-text :text="item.createtime" color="black" :size="28"></fui-text>
						</view>
						<view class="one-40">
							<fui-text text="减免：" color="#afafaf" :size="28"></fui-text>
							<fui-text :text="'￥'+parseNumber(item.records.activities_fee)" color="black" :size="28"></fui-text>
						</view>
					</view>
					<view class="line-between">
						<view class="one-60">
							<fui-text text="入场时间：" color="#afafaf" :size="28"></fui-text>
							<fui-text :text="item.records.entry_time_txt" color="black" :size="28"></fui-text>
						</view>
						<view class="one-40">
							<fui-text :text="settle_type=='after'?'账单：':'余额：'" color="#afafaf" :size="28"></fui-text>
							<merch-balance :balance="parseNumber(item.after)" :settle_type="settle_type"></merch-balance>
						</view>
					</view>
					<view class="line">
						<fui-text text="离场时间：" color="#afafaf" :size="28"></fui-text>
						<fui-text :text="item.records.exit_time_txt" color="black" :size="28"></fui-text>
					</view>
				</view>
				<view class="item" v-if="current===1">
					<view class="line">
						<fui-text text="充值时间：" color="#afafaf" :size="28"></fui-text>
						<fui-text :text="item.createtime" color="black" :size="28"></fui-text>
					</view>
					<view class="line">
						<fui-text text="充值金额：" color="#afafaf" :size="28"></fui-text>
						<fui-text :text="'￥'+parseNumber(item.payunion.pay_price)" color="black" :size="28"></fui-text>
					</view>
					<view class="line">
						<fui-text text="支付方式：" color="#afafaf" :size="28"></fui-text>
						<fui-text :text="item.payunion.pay_type_text" color="black" :size="28"></fui-text>
					</view>
				</view>
				<view class="item" v-if="current===2 && (settle_type=='before' || settle_type=='after')">
					<view class="line-between">
						<view>
							<fui-text text="交易时间：" color="#afafaf" :size="28"></fui-text>
							<fui-text :text="item.createtime" color="black" :size="28"></fui-text>
						</view>
						<view>
							<fui-text text="交易类型：" color="#afafaf" :size="28"></fui-text>
							<fui-text :text="item.log_type_txt" color="black" :size="28"></fui-text>
						</view>
					</view>
					<view class="line-between" v-if="item.payunion">
						<view>
							<fui-text text="支付方式：" color="#afafaf" :size="28"></fui-text>
							<fui-text :text="item.payunion.pay_type_text" color="black" :size="28"></fui-text>
						</view>
						<view>
							<fui-text text="实付金额：" color="#afafaf" :size="28"></fui-text>
							<fui-text :text="item.payunion.pay_price" color="black" :size="28"></fui-text>
						</view>
					</view>
					<view class="line-between">
						<view>
							<fui-text text="交易前：" color="#afafaf" :size="28"></fui-text>
							<merch-balance :balance="item.before" :settle_type="settle_type"></merch-balance>
						</view>
						<view>
							<fui-text text="变化金额：" color="#afafaf" :size="28"></fui-text>
							<fui-text :text="'￥'+item.change" color="red" :size="28"></fui-text>
						</view>
						<view>
							<fui-text text="交易后：" color="#afafaf" :size="28"></fui-text>
							<merch-balance :balance="item.after" :settle_type="settle_type"></merch-balance>
						</view>
					</view>
					<view>
						<text style="color: #afafaf;font-size: 28rpx;">交易备注：</text>
						<text style="color: black;font-size: 28rpx;">{{item.remark}}</text>
					</view>
				</view>
				<view class="item" v-if="current===2 && settle_type=='time'">
					<view class="line-between">
						<view>
							<fui-text text="交易时间：" color="#afafaf" :size="28"></fui-text>
							<fui-text :text="item.createtime" color="black" :size="28"></fui-text>
						</view>
						<view>
							<fui-text text="交易类型：" color="#afafaf" :size="28"></fui-text>
							<fui-text :text="item.log_type_txt" color="black" :size="28"></fui-text>
						</view>
					</view>
					<view class="line-between" v-if="item.payunion">
						<view>
							<fui-text text="支付方式：" color="#afafaf" :size="28"></fui-text>
							<fui-text :text="item.payunion.pay_type_text" color="black" :size="28"></fui-text>
						</view>
						<view>
							<fui-text text="实付金额：" color="#afafaf" :size="28"></fui-text>
							<fui-text :text="item.payunion.pay_price" color="black" :size="28"></fui-text>
						</view>
					</view>
					<view class="line-column">
						<view class="two">
							<fui-text text="交易前：" color="#afafaf" :size="28"></fui-text>
							<merch-balance :balance="item.before" :settle_type="settle_type"></merch-balance>
						</view>
						<view class="two">
							<fui-text text="变化金额：" color="#afafaf" :size="28"></fui-text>
							<merch-balance :balance="item.change" :settle_type="settle_type"></merch-balance>
						</view>
						<view class="two">
							<fui-text text="交易后：" color="#afafaf" :size="28"></fui-text>
							<merch-balance :balance="item.after" :settle_type="settle_type"></merch-balance>
						</view>
					</view>
					<view>
						<text style="color: #afafaf;font-size: 28rpx;">交易备注：</text>
						<text style="color: black;font-size: 28rpx;">{{item.remark}}</text>
					</view>
				</view>
			</fui-list-cell>
		</fui-list>
		<filter :param="param" @confirm="doSubmit"></filter>
		<fui-empty v-if="list.length===0" :src="`${baseUrl}assets/img/miniapp/empty.png`" title="暂无数据!" :marginTop="200"></fui-empty>
	</view>
</template>

<script>
	import {methods,baseUrl} from '@/utils/core.js';
	import {parseNumber,formatDate} from '@/utils/util.js'
	import platetype from '@/components/common/platetype.vue';
	import filter from '@/components/common/filter.vue';
	import merchBalance from '@/components/common/merch-balance.vue';
	export default {
		components:{
			platetype:platetype,
			filter:filter,
			merchBalance:merchBalance
		},
		data() {
			return {
				baseUrl:baseUrl,
				segmented:['消费账单','充值记录','余额流水'],
				settle_type:'',
				merch_id:'',
				current:0,
				list:[],
				page:1,
				endData:false,
				param:{
					starttime:'',
					endtime:''
				}
			}
		},
		onLoad(e) {
			this.merch_id=e.merch_id;
			this.settle_type=e.settle_type;
			this.getList();
		},
		onShow() {
			let refresh=uni.getStorageSync('refresh') || '';
			if(refresh){
				this.list=[];
				this.page=1;
				this.endData=false;
				uni.setStorageSync('refresh','');
				this.getList();
			}
		},
		onReachBottom() {
			this.getList();
		},
		onPullDownRefresh() {
			this.list=[];
			this.page=1;
			this.endData=false;
			this.getList(function(){
				uni.stopPullDownRefresh();
			});
		},
		methods: {
			...methods,
			parseNumber,
			formatDate:function(i){
				return formatDate(new Date(i*1000));
			},
			changeSegmented:function(e){
				this.current=e.index;
				this.list=[];
				this.page=1;
				this.endData=false;
				this.getList();
			},
			doSubmit:function(param){
				this.param=param;
				this.list=[];
				this.page=1;
				this.endData=false;
				this.getList();
			},
			getList:function(callback=false){
				this.showPopup=false;
				if(this.endData){
					this.$msg('已经到底了');
					return;
				}
				let type=['bill','recharge','balance'];
				this.$get('parking/merch/log',{
					...this.param,
					type:type[this.current],
					merch_id:this.merch_id,
					page:this.page
				},true).then(res=>{
					this.list=this.list.concat(res);
					this.page++;
					if(res.length<10){
						this.endData=true;
					}	
					if(callback){
						callback();
					}
				});
			}
		}
	}
</script>

<style lang="scss" scoped>
.item{
	display: flex;
	flex-wrap: wrap;
	.line{
		display: flex;
		align-items: center;
		width:100%;
		height: 60rpx;	
	}
	.line-between{
		display: flex;
		align-items: center;
		justify-content: space-between;
		width:100%;
		height: 60rpx;
		.one{
			display: flex;
			align-items: center;
			width: 50%;
		}
		.one-40{
			width: 40%;
		}
		.one-60{
			width: 60%;
		}
	}
	.line-column{
		display: flex;
		align-items: center;
		justify-content: space-between;
		width:100%;
		margin-top: 14rpx;
		.two{
			padding-bottom: 20rpx;
			justify-content: space-between;
			display: flex;
			flex-direction: column;
			height: 90rpx;
		}
	}
}
</style>